﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BulldogCMS.Data.ContentTree;
using System.Xml.Linq;

namespace BulldogCMS.Data.Tests
{
    [TestClass]
    public class XMLContentTreeProviderTest
    {
        private IContentTreeProvider CreateContentTreeProvider()
        {
            XDocument xDoc = XDocument.Load(TestingData.ReflectionHelper.GetResourceStream("BulldogCMS.Data.Tests.TestingData.VolksbankWeb.xml"));
            return new XMLContentTreeProvider(xDoc);
        }

        [TestMethod]
        public void LoadRootNodes()
        {
            IContentTreeProvider contentProvider = this.CreateContentTreeProvider();
            Assert.AreEqual(1, contentProvider.PartialNodes.Count(), "Root nodes does not equal to 1");
            IPartialNode rootPartialNode = contentProvider.PartialNodes.FirstOrDefault();
            Assert.AreEqual("VolksbankWeb", rootPartialNode.Name, "Name property of root node is wrong");
            Assert.AreEqual("VolksbankWeb", rootPartialNode.TemplateName, "TemplateName property of root node is wrong");
        }

        [TestMethod]
        public void LoadSubNodes()
        {
            IContentTreeProvider contentProvider = this.CreateContentTreeProvider();
            IPartialNode rootPartialNode = contentProvider.PartialNodes.FirstOrDefault();
            Assert.IsNotNull(rootPartialNode, "There should be one root node");
            Assert.AreEqual(6, rootPartialNode.SubPartialNodes.Count(), "There should be 6 subnodes under VolksbankWeb node.");
        }

    }
}
